package com.szs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.szs.common.R;
import com.szs.pojo.Category;
import com.szs.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类信息
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * 新增分类信息
     *
     * @param category
     * @return
     */
    @PostMapping
    public R<String> save(@RequestBody Category category) {
        return categoryService.add(category);
    }

    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize) {
        return categoryService.page(page,pageSize);
    }

    /**
     * 分类信息删除
     * @param id
     * @return
     */
    @DeleteMapping
    public R<String> remove(Long id) {
        return categoryService.remove(id);
    }

    @PutMapping
    public R<String> update(@RequestBody Category category) {
        return categoryService.update(category);
    }

    @GetMapping("/list")
    public R<List<Category>> list(Category category) {
        log.info("获取的分类类型：{}",category.getType());
        return categoryService.list(category);
    }
}
